package com.luo.demo;

import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;

/**
 * Created by Administrator on 2017/5/8.
 */

public class ZygoteActivity extends Activity {
    private Fragment mContentFragment;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zygote);
        Intent intent = getIntent();
        String className = intent.getStringExtra("className");
        switchFrgment(className);
    }

    public static void startActivityForResult(Context context, int requestCode, String className) {
        Intent intent = new Intent(context, ZygoteActivity.class);
        intent.putExtra("className", className);
        ((Activity) context).startActivityForResult(intent, requestCode);
    }

    public static void startActivity(Context context, String className) {
        Intent intent = new Intent(context, ZygoteActivity.class);
        intent.putExtra("className", className);
        ((Activity) context).startActivity(intent);
    }

    private void switchFrgment(String className) {
        try {
            Class<?> cls = Class.forName(className);
            mContentFragment = (Fragment) cls.newInstance();
            getFragmentManager().beginTransaction().replace(R.id.fl_zytote,mContentFragment).commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
